home *** CD-ROM | disk | FTP | other *** search
/ Mac-Source 1994 July / Mac-Source_July_1994.iso / C and C++ / Science⁄Math / Scientist's Helper src / s.helper.4 / regmanip.c < prev    next >
C/C++ Source or Header  |  1986-02-06  |  20KB  |  911 lines

  1. #include "all.h"
  2. #include "regtabext.h"
  3.  
  4. LoadSg1() /*force load of segment*/
  5. {
  6.     ;
  7. }
  8.  
  9. ColMin(col, min)
  10. int col;
  11. float *min;
  12. {
  13.     int i;
  14.     float x, y;
  15.     if (!NextNotNan( 1, col, col, &i ) ){
  16.         *min=infinity;
  17.         }
  18.     else {
  19.         GetTable(i,col,&x);
  20.         i++;
  21.         while( NextNotNan(i,col,col,&i) ) {
  22.             GetTable(i,col,&y);
  23.             if (y<x) {
  24.                 x = y;
  25.                 }
  26.             i++;
  27.             } /*end while*/
  28.         *min=x;
  29.         }
  30. }
  31.  
  32. ColMax(col,max)
  33. int col;
  34. float *max;
  35. {
  36.     int i;
  37.     float x, y;
  38.  
  39.     if (!NextNotNan( 1, col, col, &i ) ) {                   
  40.         *max=infinity;
  41.         }                   
  42.     else {
  43.         GetTable(i,col,&x);
  44.         i++;
  45.         while (NextNotNan(i,col,col,&i)) {                   
  46.             GetTable(i,col,&y);
  47.             if (y>x) {
  48.                 x = y;
  49.                 }
  50.             i++;
  51.             } /*end while*/
  52.         *max=x;
  53.         } /*end if*/
  54. }
  55.  
  56. GScan()
  57. {
  58.     int i, j; 
  59.     
  60.     SToI( command.cmdWord[1], &i );
  61.     SToI( command.cmdWord[2], &j );
  62.     if( (GoodCol(i)!=0) || (GoodCol(j)!=0) ) {
  63.         ErrMsg(noSuchColumn);
  64.         }
  65.     ColMin(i,&(graph.xMin));
  66.     ColMax(i,&(graph.xMax));
  67.     ColMin(j,&(graph.yMin));
  68.     ColMax(j,&(graph.yMax));
  69. }
  70.  
  71. ColMath()
  72. {
  73.     int xcol, ycol, result, i, rows;
  74.     float x, y;
  75.  
  76.     SToI( command.cmdWord[5], &result );
  77.     rows=table.header.rows;
  78.     if( (strcmp(command.cmdWord[2],"+")==0) || (strcmp(command.cmdWord[2],"-")==0) ||
  79.          (strcmp(command.cmdWord[2],"*")==0) || (strcmp(command.cmdWord[2],"/")==0)  )  {                   
  80.         SToI( command.cmdWord[1], &xcol );
  81.         SToI( command.cmdWord[3], &ycol );
  82.         if( strcmp(command.cmdWord[2],"+")==0 ) {
  83.             for(  i=1; i<=rows; i++ ) {
  84.                 GetTable(i,xcol,&x);
  85.                 GetTable(i,ycol,&y);
  86.                 SetTable(i,result,(x+y),FALSE);
  87.                 } /*end for*/
  88.             }
  89.         else if( strcmp(command.cmdWord[2],"-")==0 ) {
  90.             for(  i=1; i<=rows; i++ ) {
  91.                 GetTable(i,xcol,&x);
  92.                 GetTable(i,ycol,&y);
  93.                 SetTable(i,result,(x-y),FALSE);
  94.                 } /*end for*/
  95.             }
  96.         else if( strcmp(command.cmdWord[2],"*")==0 ) {
  97.             for(  i=1; i<=rows; i++ ) {
  98.                 GetTable(i,xcol,&x);
  99.                 GetTable(i,ycol,&y);
  100.                 if( NaN(&y) ) {
  101.                     SetTable(i,result,infinity,FALSE);
  102.                     }
  103.                 else {
  104.                     SetTable(i,result,(x*y),FALSE);
  105.                     }
  106.                 } /*end for*/
  107.             }
  108.         else if( strcmp(command.cmdWord[2],"/")==0 ) {
  109.             for(  i=1; i<=rows; i++ ) {
  110.                 GetTable(i,xcol,&x);
  111.                 GetTable(i,ycol,&y);
  112.                 SetTable(i,result,(x/y),FALSE);
  113.                 } /*end for*/
  114.             }
  115.         }
  116.     else if( (strcmp(command.cmdWord[2],"+#")==0) || (strcmp(command.cmdWord[2],"-#")==0) ||
  117.                 (strcmp(command.cmdWord[2],"*#")==0) || (strcmp(command.cmdWord[2],"/#")==0)  )  {                   
  118.         SToI( command.cmdWord[1], &xcol );
  119.         SToR( command.cmdWord[3], &y, TRUE );
  120.         if (strcmp(command.cmdWord[2],"+#")==0)  {                   
  121.             for (i=1; i<=rows; i++) {                   
  122.                 GetTable(i,xcol,&x);
  123.                 SetTable(i,result,(x+y),FALSE);
  124.                 } /*end for*/
  125.             }
  126.         else if (strcmp(command.cmdWord[2],"-#")==0)  {                   
  127.             for (i=1; i<=rows; i++) {                   
  128.                 GetTable(i,xcol,&x);
  129.                 SetTable(i,result,(x-y),FALSE);
  130.                 } /*end for*/
  131.             }
  132.         else if (strcmp(command.cmdWord[2],"*#")==0)  {                   
  133.             for (i=1; i<=rows; i++) {                   
  134.                 GetTable(i,xcol,&x);
  135.                 SetTable(i,result,(x*y),FALSE);
  136.                 } /*end for*/
  137.             }
  138.         else if (strcmp(command.cmdWord[2],"/#")==0)  {                   
  139.             for (i=1; i<=rows; i++) {                   
  140.                 GetTable(i,xcol,&x);
  141.                 if( NaN(&y) ) {
  142.                     SetTable(i,result,infinity,FALSE);
  143.                     }
  144.                 else {
  145.                     SetTable(i,result,(x/y),FALSE);
  146.                     }
  147.                 } /*end for*/
  148.             }
  149.         }
  150.     else if( (strcmp(command.cmdWord[2],"#+")==0) || (strcmp(command.cmdWord[2],"#-")==0) ||
  151.                 (strcmp(command.cmdWord[2],"#*")==0) || (strcmp(command.cmdWord[2],"#/")==0)  )  {                   
  152.         SToR( command.cmdWord[1], &x );
  153.         SToI( command.cmdWord[3], &ycol, TRUE );
  154.         if (strcmp(command.cmdWord[2],"#+")==0)  {                   
  155.             for (i=1; i<=rows; i++) {                   
  156.                 GetTable(i,ycol,&y);
  157.                 SetTable(i,result,(x+y),FALSE);
  158.                 } /*end for*/
  159.             }
  160.         else if (strcmp(command.cmdWord[2],"#-")==0)  {                   
  161.             for (i=1; i<=rows; i++) {                   
  162.                 GetTable(i,ycol,&y);
  163.                 SetTable(i,result,(x-y),FALSE);
  164.                 } /*end for*/
  165.             }
  166.         else if (strcmp(command.cmdWord[2],"#*")==0)  {                   
  167.             for (i=1; i<=rows; i++) {                   
  168.                 GetTable(i,ycol,&y);
  169.                 SetTable(i,result,(x*y),FALSE);
  170.                 } /*end for*/
  171.             }
  172.         else if (strcmp(command.cmdWord[2],"#/")==0)  {                   
  173.             for (i=1; i<=rows; i++) {                   
  174.                 GetTable(i,ycol,&y);
  175.                 if( NaN(&y) ) {
  176.                     SetTable(i,result,infinity,FALSE);
  177.                     }
  178.                 else {
  179.                     SetTable(i,result,(x/y),FALSE);
  180.                     }
  181.                 } /*end for*/
  182.             }
  183.         }
  184.     else {                   
  185.                  ErrMsg(noSuchModifier);
  186.         }
  187. }
  188. ColFunction()
  189. {
  190.     float x, y;
  191.     int xcol, ycol, i, rows;
  192.  
  193.     SToI( command.cmdWord[2], &xcol );
  194.     SToI( command.cmdWord[3], &ycol );
  195.     rows=table.header.rows;
  196.     if (strcmp(command.cmdWord[1],"sin")==0) {
  197.         for (i=1; i<=rows; i++) {
  198.             GetTable( i, xcol, &x );
  199.             errno = 0;
  200.             x = (float) sin( (double)x );
  201.             ToNaN( &x );
  202.             SetTable( i, ycol, x, FALSE );
  203.             } /*end for*/
  204.         }
  205.     else if (strcmp(command.cmdWord[1],"cos")==0) {
  206.         for (i=1; i<=rows; i++) {
  207.             GetTable( i, xcol, &x );
  208.             errno = 0;
  209.             x = (float) cos( (double)x );
  210.             ToNaN( &x );
  211.             SetTable( i, ycol, x, FALSE );
  212.             } /*end for*/
  213.         }
  214.     else if (strcmp(command.cmdWord[1],"tan")==0) {
  215.         for (i=1; i<=rows; i++) {
  216.             GetTable( i, xcol, &x );
  217.             errno = 0;
  218.             x = (float) tan( (double)x );
  219.             ToNaN( &x );
  220.             SetTable( i, ycol, x, FALSE );
  221.             } /*end for*/
  222.         }
  223.     else if (strcmp(command.cmdWord[1],"asin")==0) {
  224.         for (i=1; i<=rows; i++) {
  225.             GetTable( i, xcol, &x );
  226.             errno = 0;
  227.             x = (float) asin( (double)x );
  228.             ToNaN( &x );
  229.             SetTable( i, ycol, x, FALSE );
  230.             } /*end for*/
  231.         }
  232.     else if (strcmp(command.cmdWord[1],"acos")==0) {
  233.         for (i=1; i<=rows; i++) {
  234.             GetTable( i, xcol, &x );
  235.             errno = 0;
  236.             x = (float) acos( (double)x );
  237.             ToNaN( &x );
  238.             SetTable( i, ycol, x, FALSE );
  239.             } /*end for*/
  240.         }
  241.     else if (strcmp(command.cmdWord[1],"atan")==0) {
  242.         for (i=1; i<=rows; i++) {
  243.             GetTable( i, xcol, &x );
  244.             errno = 0;
  245.             x = (float) atan( (double)x );
  246.             ToNaN( &x );
  247.             SetTable( i, ycol, x, FALSE );
  248.             } /*end for*/
  249.         }
  250.     else if (strcmp(command.cmdWord[1],"exp")==0) {
  251.         for (i=1; i<=rows; i++) {
  252.             GetTable( i, xcol, &x );
  253.             errno = 0;
  254.             x = (float) exp( (double)x );
  255.             ToNaN( &x );
  256.             SetTable( i, ycol, x, FALSE );
  257.             } /*end for*/
  258.         }
  259.     else if (strcmp(command.cmdWord[1],"erf")==0) {
  260.         for (i=1; i<=rows; i++) {
  261.             GetTable( i, xcol, &x );
  262.             errno = 0;
  263.             errfcn( x, &x,&y,&y,&y,&y );
  264.             ToNaN( &x );
  265.             SetTable( i, ycol, x, FALSE );
  266.             } /*end for*/
  267.         }
  268.     else if (strcmp(command.cmdWord[1],"erfc")==0) {
  269.         for (i=1; i<=rows; i++) {
  270.             GetTable( i, xcol, &x );
  271.             errno = 0;
  272.             errfcn( x, &y,&x,&y,&y,&y );
  273.             ToNaN( &x );
  274.             SetTable( i, ycol, x, FALSE );
  275.             } /*end for*/
  276.         }
  277.     else if (strcmp(command.cmdWord[1],"ln")==0) {
  278.         for (i=1; i<=rows; i++) {
  279.             GetTable( i, xcol, &x );
  280.             errno = 0;
  281.             x = (float) log( (double)x );
  282.             ToNaN( &x );
  283.             SetTable( i, ycol, x, FALSE );
  284.             } /*end for*/
  285.         }
  286.     else if (strcmp(command.cmdWord[1],"sqrt")==0) {
  287.         for (i=1; i<=rows; i++) {
  288.             GetTable( i, xcol, &x );
  289.             errno = 0;
  290.             x = (float) sqrt( (double)x );
  291.             ToNaN( &x );
  292.             SetTable( i, ycol, x, FALSE );
  293.             } /*end for*/
  294.         }
  295.     else if (strcmp(command.cmdWord[1],"row")==0) {
  296.         y = (float)table.header.rows;
  297.         for (i=1; i<=rows; i++) {
  298.             GetTable( i, xcol, &x );
  299.             x = 1.0 + ((x-table.header.start)/table.header.samp);
  300.             if( x<1.0 ) {
  301.                 x=1.0;
  302.                 }
  303.             else if( x>y ) {
  304.                 x=y;
  305.                 }
  306.             SetTable( i, ycol, x, FALSE );
  307.             } /*end for*/
  308.         }
  309.     else {
  310.                  ErrMsg(badModifier);
  311.         }
  312. }
  313. InsCommand()
  314. {
  315.     int i, j;
  316.     SToI( command.cmdWord[2], &i );
  317.     if( strlen(command.cmdWord[3])==0 ) {
  318.         strcpy( command.cmdWord[3],"1" );
  319.         }
  320.     SToI( command.cmdWord[3], &j );
  321.     
  322.     if( strcmp(command.cmdWord[1],"col")==0 ) {
  323.         InsertCol(i,j);
  324.         }
  325.     else if( strcmp(command.cmdWord[1],"row")==0 ) {
  326.         InsertRow(i,j);
  327.         }
  328.     else {
  329.         ErrMsg( badModifier );
  330.         }
  331. }    
  332.  
  333. InsertRow( jRow, many )
  334. int jRow, many;
  335. {
  336.     int nRow, nCol, mRow, mCol, iRow, iCol;
  337.     float x;
  338.     
  339.     nRow = table.header.rows;
  340.     nCol = table.header.cols;
  341.     mRow = table.header.maxRows;
  342.     mCol = table.header.maxCols;
  343.     
  344.     if( (nRow+many)>mRow ) {
  345.         ErrMsg("table would exceed allocated space");
  346.         }
  347.     else if (many<=0) {
  348.         ErrMsg("bad number of rows");
  349.         }
  350.     else if (table.header.interpolated) { 
  351.         ErrMsg("cant change row 1 of interpolated table");
  352.         }                   
  353.     else if( GoodRow(jRow)!=0 ) {
  354.         ErrMsg(noSuchRow);
  355.         }                   
  356.     else { 
  357.         nRow += many;
  358.         table.header.rows=nRow;
  359.         for (iRow=nRow;  iRow>=(jRow+many); iRow-- ) {
  360.         for (iCol=1; iCol<=nCol; iCol++) {
  361.             GetTable((iRow-many),iCol,&x);
  362.             SetTable(iRow,iCol,x,FALSE);
  363.             } /*end for iCol*/
  364.             } /*end for iRow*/
  365.         for (iRow=1; iRow<=many; iRow++) {
  366.         for (iCol=1;  iCol<=nCol; iCol++) {
  367.             SetTable( (jRow+iRow-1), iCol, infinity, FALSE );
  368.             } /*end for iCol*/
  369.             } /*end for iRow*/
  370.         Header2Vars();
  371.         } /*end if*/
  372. }
  373.  
  374.  
  375. InsertCol( jCol, many)
  376. int jCol, many;
  377. {
  378.     int nRow, nCol, mRow, mCol, iRow, iCol;
  379.     float x;
  380.  
  381.     nRow = table.header.rows;
  382.     nCol = table.header.cols;
  383.     mRow = table.header.maxRows;
  384.     mCol = table.header.maxCols;
  385.     
  386.     if( (nCol+many)>mCol ) {
  387.         ErrMsg("table would exceed allocated space");
  388.         }
  389.     else if (many<=0) {
  390.         ErrMsg("bad number of rows");
  391.         }
  392.     else if( table.header.interpolated && (jCol=1) ) {
  393.         ErrMsg("cant change row 1 of interpolated table");
  394.         }
  395.     else if( GoodCol(jCol)!=0 ) {
  396.         ErrMsg( noSuchColumn );
  397.         }
  398.     else {
  399.         nCol += many;
  400.         table.header.cols=nCol;
  401.         for (iCol=nCol; iCol>=(jCol+many); iCol--) {
  402.             strcpy(table.header.colName[iCol-1],table.header.colName[iCol-many-1]);
  403.             for (iRow=1; iRow<=nRow; iRow++) {    
  404.                 GetTable(iRow,(iCol-many),&x);
  405.                 SetTable(iRow,iCol,x,FALSE);
  406.                 } /*end for iRow*/
  407.             } /*end for iCol*/
  408.         for (iCol=jCol; iCol<=(jCol+many-1); iCol++ ) {                   
  409.             strcpy(table.header.colName[iCol-1],"");
  410.             for (iRow=1; iRow<=nRow; iRow++) {                   
  411.                 SetTable( iRow, iCol, infinity, FALSE );
  412.                 } /*end for iRow*/
  413.             } /*end for iCol*/
  414.         Header2Vars();
  415.         } /*end if*/
  416. }
  417.  
  418. DelCommand()
  419. {
  420.     int i, j;
  421.     SToI( command.cmdWord[2], &i );
  422.     if( strlen(command.cmdWord[3])==0 ) {
  423.         strcpy( command.cmdWord[3],"1" );
  424.         }
  425.     SToI( command.cmdWord[3], &j );
  426.     
  427.     if( strcmp(command.cmdWord[1],"col")==0 ) {
  428.         DeleteCol(i,j);
  429.         }
  430.     else if( strcmp(command.cmdWord[1],"row")==0 ) {
  431.         DeleteRow(i,j);
  432.         }
  433.     else {
  434.         ErrMsg( badModifier );
  435.         }
  436. }
  437.  
  438. DeleteRow( jRow, many)
  439. int jRow, many;
  440. {
  441.     int nRow, nCol, mRow, mCol, iRow, iCol;
  442.     float x;
  443.     nRow = table.header.rows;
  444.     nCol = table.header.cols;
  445.     mRow = table.header.maxRows;
  446.     mCol = table.header.maxCols;
  447.     
  448.     if (many<=0)  {
  449.         ErrMsg("bad number of rows");
  450.         }
  451.     else if( (nRow-jRow+1)<many ) {
  452.         ErrMsg("attempt to delete off bottom of table");
  453.         }
  454.     else if( (nRow-many)<1 ) {
  455.         ErrMsg("resulting table would have no rows");
  456.         }
  457.     else if (table.header.interpolated) {
  458.         ErrMsg("cant change row 1 of interpolated table");
  459.         }
  460.     else if( GoodRow(jRow)!=0 ) {
  461.         ErrMsg(noSuchRow);
  462.         }
  463.     else {
  464.         nRow -= many;
  465.         for (iRow=jRow; iRow<=nRow; iRow++) {                   
  466.         for (iCol=1; iCol<=nCol; iCol++) {
  467.             GetTable((iRow+many),iCol,&x);
  468.             SetTable(iRow,iCol, x,FALSE);
  469.             } /*end for iCol*/
  470.             } /*end for iRow*/
  471.         table.header.rows = nRow;
  472.         Header2Vars();
  473.         } /*end if*/
  474. }
  475.  
  476. DeleteCol( jCol, many)
  477. int jCol, many;
  478. {
  479.     int nRow, nCol, mRow, mCol, iRow, iCol;
  480.     float x;
  481.  
  482.     nRow = table.header.rows;
  483.     nCol = table.header.cols;
  484.     mRow = table.header.maxRows;
  485.     mCol = table.header.maxCols;
  486.     
  487.     if (many<=0) {
  488.         ErrMsg("bad number of Cols");
  489.         }
  490.     else if( (nCol-many)<1 ) {
  491.         ErrMsg("resulting table would have no columns");
  492.         }
  493.     else if( (nCol-jCol+1)<many ) {
  494.         ErrMsg("attempt to delete of edge of table");
  495.         }
  496.     else if( table.header.interpolated && (jCol=1) ) {
  497.         ErrMsg("cant change row 1 of interpolated table");
  498.         }
  499.     else if( GoodCol(jCol)!=0 ) {
  500.         ErrMsg(noSuchColumn);
  501.         }
  502.     else {
  503.         nCol -= many;
  504.         for (iCol=jCol; iCol<= nCol; iCol++)  {
  505.             strcpy(table.header.colName[iCol-1],table.header.colName[iCol+many-1]);
  506.             for( iRow=1; iRow<=nRow; iRow++) {
  507.                 GetTable(iRow,(iCol+many),&x);
  508.                 SetTable(iRow,iCol,x,FALSE);
  509.                 } /*end for iRow*/
  510.             } /*end for iCol*/
  511.         table.header.cols = nCol;
  512.         Header2Vars();
  513.         } /*end if*/
  514. }
  515.  
  516. SwapCommand()
  517. {
  518.     int i, j;
  519.     SToI( command.cmdWord[2], &i );
  520.     SToI( command.cmdWord[3], &j );
  521.     if( strcmp(command.cmdWord[1],"col")==0 ) {
  522.         SwapCol(i,j);
  523.         }
  524.     else if( strcmp(command.cmdWord[1],"row")==0 ) {
  525.         SwapRow(i,j);
  526.         }
  527.     else {
  528.         ErrMsg( badModifier );
  529.         }
  530. }    
  531.  
  532. SwapRow( i, j )
  533. int i, j;
  534. {
  535.     float x, y;
  536.     int k;
  537.     
  538.     for( k=1; k<=table.header.cols; k++ ) {
  539.         GetTable(i,k,&x);
  540.         GetTable(j,k,&y);
  541.         SetTable(i,k,y,FALSE);
  542.         SetTable(j,k,x,FALSE);
  543.         }
  544. }
  545.  
  546. SwapCol( i, j )
  547. int i, j;
  548. {
  549.     float x, y;
  550.     int k;
  551.     char s[cmdWordLen];
  552.  
  553.     for( k=1; k<=table.header.rows; k++) {
  554.         GetTable(k,i,&x);
  555.         GetTable(k,j,&y);
  556.         SetTable(k,i,y,FALSE);
  557.         SetTable(k,j,x,FALSE);
  558.         }
  559.     strcpy(s,table.header.colName[i-1]);
  560.     strcpy(table.header.colName[i-1],table.header.colName[j-1]);
  561.     strcpy(table.header.colName[j-1],s);
  562. }
  563.  
  564. CopyCommand()
  565. {
  566.     int i, j;
  567.     
  568.     SToI( command.cmdWord[2], &i );
  569.     SToI( command.cmdWord[3], &j );
  570.     if( strcmp(command.cmdWord[1],"col")==0 ) {
  571.         CopyCol(i,j);
  572.         }
  573.     else if( strcmp(command.cmdWord[1],"row")==0 ) {
  574.         CopyRow(i,j);
  575.         }
  576.     else {
  577.         ErrMsg( badModifier );
  578.         }
  579. }
  580.  
  581. CopyRow( fromRow, toRow)
  582. int fromRow, toRow;
  583. {
  584.     int k;
  585.     float x;
  586.     
  587.     for( k=1; k<=table.header.cols; k++ ) {
  588.         GetTable(fromRow,k,&x);
  589.         SetTable(toRow,k,x,FALSE);
  590.         }
  591. }
  592.  
  593. CopyCol( fromCol, toCol )
  594. int fromCol, toCol;
  595. {
  596.     int k;
  597.     float x;
  598.  
  599.     for( k=1; k<=table.header.rows; k++ ) {
  600.         GetTable(k,fromCol,&x);
  601.         SetTable(k,toCol,x,FALSE);
  602.         }
  603.     strcpy( table.header.colName[toCol-1],table.header.colName[fromCol-1]);
  604. }
  605. Header2Vars() /*copy some header variables to macro sub variable table*/
  606.           /* also redo title of edit window */
  607. {
  608.     int status;
  609.     char str[120];
  610.     
  611.     strcpy( str, "Edit Window for " );
  612.     strcat( str, table.header.title );
  613.     if( strlen(str)>35 ) {
  614.         str[31]='.';
  615.         str[32]='.';
  616.         str[33]='.';
  617.         str[34]='\0';
  618.         }
  619.     SetWTitle( theWindow[edWindow], ctop(str) );
  620.          
  621.     status = TRUE;
  622.     if (table.header.interpolated) strcpy( str, "true"); else strcpy( str, "false");
  623.     status  = status && SetVar("interpolated",str);
  624.     
  625.     IToS( table.header.rows, str );
  626.     status  = status && SetVar("rows",str);
  627.     
  628.     IToS( table.header.cols, str );
  629.     status  = status && SetVar("cols",str);
  630.     
  631.     RToS( table.header.start, str );
  632.     status = status && SetVar("start",str);
  633.     
  634.     RToS( table.header.samp, str );
  635.     status = status && SetVar("samp",str);
  636.     
  637.     status = status && SetVar("title",table.header.title);
  638.     
  639.     if (!status) {
  640.         ErrMsg("no space to create header variables");
  641.         }
  642. }
  643.  
  644. CreateCol1()  /*fills in column 1*/
  645. {
  646.     int row;
  647.     
  648.     if (table.header.interpolated) {
  649.         for (row=1; row<=table.header.rows; row++ ) { 
  650.             SetTable( row, 1, (table.header.start+table.header.samp*(row-1)), TRUE );
  651.             } /*end for*/
  652.         } /*end if*/
  653. }
  654.  
  655. InitHeader() /*initializes some header variables*/
  656. {
  657.     int i;
  658.     char str[80];
  659.      
  660.     table.header.interpolated  = FALSE;
  661.     table.header.start = 0.0;
  662.     table.header.samp = 1.0;
  663.     strcpy( table.header.title, "");
  664.     for (i=0; i<table.header.cols; i++ ) {                   
  665.         IToS( i, str );
  666.         strcpy( table.header.colName[i], "Col " );
  667.         strcat( table.header.colName[i], str );
  668.         }
  669.     Header2Vars();
  670. }
  671.  
  672. IToS( i, s ) /*integer to string conversion*/
  673. int i;
  674. char s[];
  675. {
  676.     int j, k;
  677.     sprintf( s, "%-6d", i );
  678.     k = strlen( s );
  679.     for( j=0; j<k; j++ ) { /*clip trailing blanks*/
  680.         if( s[j]==' ' ) {
  681.             s[j]='\0';
  682.             break;
  683.             }
  684.         }
  685. }
  686.  
  687. RToS( f, s ) /*float to string conversion*/
  688. float f;
  689. char s[];
  690. {
  691.     int j, k;
  692.     if( (f>-10000.0) && (f<10000.0) ) {
  693.         ftoa( (double)f, s, 5, 2 );
  694.         }
  695.     else {
  696.         ftoa( (double)f, s, 4, 0 );
  697.         }
  698.     for( j=0; j<80; j++ ) { /*clip trailing blanks*/
  699.         if( s[j]=='\0' ) {
  700.             break;
  701.             }
  702.         else if( s[j]==' ' ) {
  703.             s[j]='\0';
  704.             break;
  705.             } /*end if*/
  706.         } /*end for*/
  707.     if( ((s[0]=='+') && (s[1]=='+')) || ((s[0]=='-') && (s[1]=='-')) ) {
  708.         strcpy( s, "NaN");
  709.         }
  710. }
  711.  
  712. SToR( s, f, NaNsOK ) /*string to float conversion*/
  713. char s[];
  714. float *f;
  715. int NaNsOK;
  716. {
  717.     *f = infinity;
  718.     sscanf( s, "%e", f );
  719.     if( (!NaNsOK) && NaN(f) ) {
  720.         ErrMsg("string to real conversion error");
  721.         }
  722. }
  723.  
  724. SToI( s, i ) /*string to integer conversion*/
  725. char s[];
  726. int *i;
  727. {
  728.     int error;
  729.     float f;
  730.     
  731.     SToR( s, &f, TRUE );
  732.     if( (NaN(&f)) || (f<-32767.0) || (f>32767.0) ) {
  733.         ErrMsg("string to integer conversion error");
  734.         }
  735.     else {
  736.         if( f>0.0 ) {
  737.             *i = (int)(f+0.5);
  738.             }
  739.         else {
  740.             *i = (int)f;
  741.             }
  742.         }
  743. }
  744.  
  745. NaN( f ) /*returns TRUE if f is a NaN or +/- Inf*/
  746. float *f;
  747. {
  748.     unsigned long mask=017740000000;
  749.     int e;
  750.     union bb {
  751.         unsigned long i;
  752.         float y;
  753.         } b;
  754.         
  755.     b.y = (*f);
  756.     e = (int)((b.i&mask)>>23);
  757.  
  758.     if( e==255 ) {
  759.         return(TRUE);
  760.         }
  761.     else {
  762.         return(FALSE);
  763.         }
  764. }
  765. VFunctionCommand()
  766. {
  767.     float x, y, z;
  768.     char vValue[cmdWordLen];
  769.     
  770.     SToR( command.cmdWord[2], &x, TRUE );
  771.     
  772.     errno = 0;
  773.     
  774.     if( strcmp(command.cmdWord[1],"sin")==0 ) {
  775.         z= sin(x);
  776.         }
  777.     else if( strcmp(command.cmdWord[1],"cos")==0 ) {
  778.         z= cos(x);
  779.         }
  780.     else if( strcmp(command.cmdWord[1],"tan")==0 ) {
  781.         z= tan(x);
  782.         }
  783.     else if( strcmp(command.cmdWord[1],"asin")==0 ) {
  784.         z= asin(x);
  785.         }
  786.     else if( strcmp(command.cmdWord[1],"acos")==0 ) {
  787.         z= acos(x);
  788.         }
  789.     else if( strcmp(command.cmdWord[1],"atan")==0 ) {
  790.         z= atan(x);
  791.         }
  792.     else if( strcmp(command.cmdWord[1],"sqrt")==0 ) {
  793.         z= sqrt(x);
  794.         }
  795.     else if( strcmp(command.cmdWord[1],"ln")==0 ) {
  796.         z= log(x);
  797.         }
  798.     else if( strcmp(command.cmdWord[1],"exp")==0 ) {
  799.         z= exp(x);
  800.         }
  801.     else if( strcmp(command.cmdWord[1],"erf")==0 ) {
  802.         errfcn( x, &z,&y,&y,&y,&y );
  803.         }
  804.     else if( strcmp(command.cmdWord[1],"erfc")==0 ) {
  805.         errfcn( x, &y,&z,&y,&y,&y );
  806.         }
  807.     else if( strcmp(command.cmdWord[1],"row")==0 ) {
  808.         z= ((x-table.header.start)/table.header.samp) + 1.0;
  809.         if( z<1.0 ) {
  810.             z=1.0;
  811.             }
  812.         else if (z>(float)table.header.rows) {
  813.             z = (float)table.header.rows;
  814.             }
  815.         }
  816.     else {
  817.         ErrMsg( noSuchModifier );
  818.         }
  819.     if( (errno==EDOM) || (errno==ERANGE) ) {
  820.         z = infinity;
  821.         errno=0;
  822.         }
  823.     RToS(z, vValue);
  824.     if( !SetVar(command.cmdWord[3],vValue) ){
  825.         ErrMsg("couldnt create variable");
  826.         }
  827. }
  828.  
  829. IfCommand()
  830. {
  831.     int i, numLines, comparison;
  832.     float x, y;
  833.     comparison = FALSE;
  834.     
  835.     if( strlen(command.cmdWord[4])==0 ) {
  836.         strcpy(command.cmdWord[4],"1");
  837.         }
  838.     SToI( command.cmdWord[4], &numLines );
  839.     if( strcmp(command.cmdWord[2],"s=")==0 ) {
  840.         if( strcmp(command.cmdWord[1],command.cmdWord[3])==0 ) {
  841.             comparison=TRUE;
  842.             }
  843.         }
  844.     else if( strcmp(command.cmdWord[2],"s<>")==0 ) {
  845.         if( strcmp(command.cmdWord[1],command.cmdWord[3])!=0 ) {
  846.             comparison=TRUE;
  847.             }
  848.         }
  849.     else if( strcmp(command.cmdWord[2],"=")==0 ) {
  850.         SToR( command.cmdWord[1], &x, TRUE );
  851.         SToR( command.cmdWord[3], &y, TRUE );
  852.         if ( NaN(&x) ) x=infinity;
  853.         if ( NaN(&y) ) y=infinity;
  854.         if( x==y ) {
  855.             comparison=TRUE;
  856.             }
  857.         }
  858.     else if( strcmp(command.cmdWord[2],"<>")==0 ) {
  859.         SToR( command.cmdWord[1], &x, TRUE );
  860.         SToR( command.cmdWord[3], &y, TRUE );
  861.         if ( NaN(&x) ) x=infinity;
  862.         if ( NaN(&y) ) y=infinity;
  863.         if( x!=y ) {
  864.             comparison=TRUE;
  865.             }
  866.         }
  867.     else if( strcmp(command.cmdWord[2],"<")==0 ) {
  868.         if ( NaN(&x) ) x=infinity;
  869.         if ( NaN(&y) ) y=infinity;
  870.         SToR( command.cmdWord[1], &x, TRUE );
  871.         SToR( command.cmdWord[3], &y, TRUE);
  872.         if( x<y ) {
  873.             comparison=TRUE;
  874.             }
  875.         }
  876.     else if( strcmp(command.cmdWord[2],">")==0 ) {
  877.         if ( NaN(&x) ) x=infinity;
  878.         if ( NaN(&y) ) y=infinity;
  879.         SToR( command.cmdWord[1], &x, TRUE );
  880.         SToR( command.cmdWord[3], &y, TRUE );
  881.         if( x>y ) {
  882.             comparison=TRUE;
  883.             }
  884.         }
  885.     else if( strcmp(command.cmdWord[2],"<=")==0 ) {
  886.         if ( NaN(&x) ) x=infinity;
  887.         if ( NaN(&y) ) y=infinity;
  888.         SToR( command.cmdWord[1], &x, TRUE );
  889.         SToR( command.cmdWord[3], &y, TRUE );
  890.         if( x<=y ) {
  891.             comparison=TRUE;
  892.             }
  893.         }
  894.     else if( strcmp(command.cmdWord[2],">=")==0 ) {
  895.         if ( NaN(&x) ) x=infinity;
  896.         if ( NaN(&y) ) y=infinity;
  897.         SToR( command.cmdWord[1], &x, TRUE );
  898.         SToR( command.cmdWord[3], &y, TRUE );
  899.         if( x>=y ) {
  900.             comparison=TRUE;
  901.             }
  902.         }
  903.     if( !comparison ) {
  904.         i = mem.stack[ mem.stackPtr ] + numLines;
  905.         if( i>=(*prText)->nLines ) {
  906.             ErrMsg("attempt to jump off end of procedure memory");
  907.             }
  908.         mem.stack[mem.stackPtr] = i;
  909.         }
  910. }
  911.